package cn.gson.springboot.model.service.afterservice;

import cn.gson.springboot.model.dao.afterdao.ComplainDao;
import cn.gson.springboot.model.mapper.aftermapper.ComplainMapper;
import cn.gson.springboot.model.pjos.Complain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ComplainService {
    @Autowired
    ComplainDao dao;
    @Autowired
    ComplainMapper mapper;

    //分页查询投诉表
    public List<Complain> selectPageHelper(Integer states, String search){
        return mapper.comPage(states,search);
    }

    //新增投诉表
    public void addPlan(Complain plan){
        plan.setPlanDelete(1);
        dao.save(plan);
    }

    //根据投诉id查询投诉表
    public Complain selectPlan(Integer planId){
       return mapper.planAll(planId);
    }

    //逻辑删除
    public void deleteByPlanId(Integer planId){
        if(planId != null){
            Complain plan = dao.findById(planId).get();
            plan.setPlanDelete(0);
            dao.save(plan);
        }
    }

    //投诉花费时间分布
    public List<Complain> selectPlanByDate(){
        return mapper.planByDate();
    }

    //投诉类型分布
    public List<Complain> selectPlanByClass(){
        return mapper.planByClass();
    }

    //投诉月度统计月份
    public List<String> selectDateByMonth(){
        return mapper.dateByMonth();
    }

    //投诉月度统计数
    public List<Integer> selectDateByCount(){
        return mapper.dateByCount();
    }

    //客户投诉次数统计名称
    public List<String> selectCustomByName(){
        return mapper.customByName();
    }

    //客户投诉次数月度统计数
    public List<Integer> selectCustomByCount(){
        return mapper.customByCount();
    }
}
